package com.arrcen.medicen.core.match.ctrl;

import com.alibaba.fastjson.JSON;
import com.arrcen.medicen.core.match.helper.TokenHelper;
import com.arrcen.medicen.core.match.model.Menu;
import com.arrcen.medicen.core.match.model.TokenUser;
import com.arrcen.medicen.core.match.model.dto.DtoSyncTable;
import com.arrcen.medicen.core.match.model.dto.Result;
import com.arrcen.medicen.core.match.model.dto.ResultObj;
import com.arrcen.medicen.core.match.model.dto.ResultUser;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("Api")
public class AuthController {

    @RequestMapping(value = "login", method = RequestMethod.POST)
    @ApiOperation(value = "用户登录")
    public ResultObj<ResultUser> login(@RequestBody TokenUser user) {
        ResultUser resultUser = new ResultUser();
        user.setId("1");
        resultUser.setToken(TokenHelper.getToken(user));
        resultUser.setUserName("测试用户");
        String menuStr="[\n" +
                "          {\n" +
                "            name:'Index',\n" +
                "            meta:{\n" +
                "              icon:'icon-home-fill',\n" +
                "              title:'首页'\n" +
                "            }\n" +
                "          },\n" +
                "          {\n" +
                "            name:'sync',\n" +
                "            meta:{\n" +
                "              icon:'icon-wallet1',\n" +
                "              title:'配置'\n" +
                "            },\n" +
                "            children: [\n" +
                "              {\n" +
                "                name:'sync',\n" +
                "                meta: {\n" +
                "                  title: '配置管理',\n" +
                "                  icon: 'icon-form-fill',\n" +
                "                },\n" +
                "              },\n" +
                "              {\n" +
                "                name:'schedule',\n" +
                "                meta: {\n" +
                "                  title: '调度记录',\n" +
                "                  icon: 'icon-shuffling-banner-fill',\n" +
                "                },\n" +
                "              },\n" +
                "            ],\n" +
                "          }]";
        resultUser.setMenus(JSON.parseArray(menuStr, Menu.class));
        ResultObj<ResultUser> result = new ResultObj<>(1,resultUser);
        return result;
    }
}
